package yx.action;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.ResumeServiceInt;
import yx.vo.JsonVO;
import yx.vo.ResumeVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "resumeAction")
public class ResumeAction extends BaseAction implements ModelDriven<ResumeVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(ResumeAction.class);

	private ResumeVO resume = new ResumeVO();

	@Override
	public ResumeVO getModel() {
		return resume;
	}

	private ResumeServiceInt resumeService;

	public ResumeServiceInt getResumeService() {
		return resumeService;
	}

	@Autowired
	public void setResumeService(ResumeServiceInt resumeService) {
		this.resumeService = resumeService;
	}

	public void queryResume() {
		/*
		 * TODO：需要调查为什么加判定
		 */
		if (resume.getStudentId() != null) {
			super.writeJson(resumeService.datagrid(resume));
		}
	}

	public void addResume() {
		JsonVO j = new JsonVO();
		try {
			ResumeVO u = resumeService.save(resume);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void removeResume() {
		resumeService.remove(resume.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void editResume() {
		ResumeVO u = resumeService.edit(resume);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}
}
